package com.gongpingjialoan.activity.car;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.main.BaseActivity;
import com.gongpingjialoan.bean.car.MainTainBean;

/**
 * Created by Administrator on 2015/11/5.
 */
public class MainTainSuccessActivity  extends BaseActivity {

    private MainTainBean mainTainBean;

    private LinearLayout linearLayout;

    private View backV;

    private TextView mileTextView , priceTextView ,feiyongTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maintain_success);
        setTitle("维修保养");

        mainTainBean = (MainTainBean) getIntent().getSerializableExtra("maintainbean");
        linearLayout = (LinearLayout)this.findViewById(R.id.price_layout);
        mileTextView = (TextView) findViewById(R.id.mile);
        priceTextView = (TextView) findViewById(R.id.price);
        feiyongTextView = (TextView) findViewById(R.id.feiyong);

        if(mainTainBean!=null){
            if(mainTainBean.getPrice()==0){
                linearLayout.setVisibility(View.GONE);
            }else {
                priceTextView.setText(mainTainBean.getPrice() + "");
                linearLayout.setVisibility(View.VISIBLE);
            }
            mileTextView.setText("["+mainTainBean.getTitle()+"]");
            int size = mainTainBean.getProjects().size();
            StringBuilder sb = new StringBuilder();
            for (int i = 0 ; i <size ; i++){
                sb.append(mainTainBean.getProjects().get(i).getName()).append(" x1\n");
            }
            feiyongTextView.setText(sb.toString());
        }

    }

    @Override
    public void initTitleBar() {
        backV = findViewById(R.id.title_back);
        backV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gotoLikeCar();
            }
        });
    }

    @Override
    public void onBackPressed() {
        gotoLikeCar();
    }

    public void gotomain(View v){
        gotoLikeCar();
    }

    private  void  gotoLikeCar(){
       setResult(Activity.RESULT_OK);finish();
    }

}
